<template>
  <div class="indexContainer">
    <navbar :navs="navs" :chooseItem="chooseItem" />
    <v-touch @swipeleft="onSwipeleft" @swiperight="onSwipeRight" :priority="1">
      <transition :name="transitionName">
        <keep-alive>
          <router-view class="router" />
        </keep-alive>
      </transition>
    </v-touch>
  </div>
</template>

<script>
/* eslint-disable no-unused-vars */

import navbar from '../../components/common/NavBar';

export default {
  name: 'index',
  components: {
    navbar,
  },
  data() {
    return {
      transitionName: 'slide-right',
      selected: 'specialSale',
      navs: ['特卖', '母婴', '服饰', '鞋包', '食品'],
      chooseItem: 0,
    };
  },
  methods: {
    onSwipeleft() {

    },
    onSwipeRight() {

    },
  },
  created() {
    this.$router.push('/home/specialSale');
  },
  computed: {
    getNavStateIndex() {
      return this.$store.state.navStateIndex;
    },
  },
  watch: {
    // 监听路由跳转
    $route(to, from) {
      console.log(`-$route-to--${to} -from--${from}`);
    },

    // 监听navStateIndex
    getNavStateIndex(state) {
      console.log(`-getNavStateIndex-state--${state}`);
      switch (state) {
        case 0:
          this.$router.push('/home/specialSale');
          break;
        case 1:
          this.$router.push('/home/infant');
          break;
        case 2:
          this.$router.push('/home/costume');
          break;
        case 3:
          this.$router.push('/home/shoe');
          break;
        case 4:
          this.$router.push('/home/food');
          break;
        default:
          this.$router.push('/home/specialSale');
          break;
      }
    },
  },
};
</script>

<style scoped>
  .router {
    width: 100%;
    transition: all 0.4s ease;
  }

  .router.slide-left-enter,.router.slide-right-leave-active {
    opacity: 0;
    transform: translateX(100%);
  }

  .router.slide-left-leave-active,.router.slide-right-enter {
    opacity: 0;
    transform: translateX(-100%);
  }
</style>
